<?php
namespace App\Http\Controllers\Api\v1\Astro;

use App\Http\Controllers\Api\v1\Astro\CompositeController;
use App\Http\Controllers\Api\v1\Astro\CompositeprogressionsController;
use App\Http\Controllers\Api\v1\Astro\CompositethirdprogressedController;
use App\Http\Controllers\Api\v1\Astro\DavisonController;
use App\Http\Controllers\Api\v1\Astro\FirdariaController;
use App\Http\Controllers\Api\v1\Astro\LunarreturnController;
use App\Http\Controllers\Api\v1\Astro\MarksController;
use App\Http\Controllers\Api\v1\Astro\NatalController;
use App\Http\Controllers\Api\v1\Astro\NowController;
use App\Http\Controllers\Api\v1\Astro\ProfectionController;
use App\Http\Controllers\Api\v1\Astro\ProgressionsController;
use App\Http\Controllers\Api\v1\Astro\ProgressionsvsnatalController;
use App\Http\Controllers\Api\v1\Astro\SolarController;
use App\Http\Controllers\Api\v1\Astro\SolarreturnController;
use App\Http\Controllers\Api\v1\Astro\SynastryController;
use App\Http\Controllers\Api\v1\Astro\ThirdprogressedController;
use App\Http\Controllers\Api\v1\Astro\TransitsController;
use App\Http\Controllers\Api\BaseController;

use Illuminate\Http\Request;

class AstroDataController extends BaseController
{
    /**
     * 获取星盘配置
     */
    public function read(Request $request)
    {
        $datetime  = htmlspecialchars($request->input('datetime'));
        $id        = $request->input('id', 0);
        $timezone  = $request->input('timezone', 8);
        $chart     = htmlspecialchars($request->input('chart'));
        $tid       = $request->input('tid', 1);
        $longitude = number_format(floatval($request->input('longitude')), 8);
        $latitude  = number_format(floatval($request->input('latitude')), 8);

        $id1 = $request->input('id1');
        $id2 = $request->input('id2');

        switch ($chart) {
            case 'now':
                $nowModel = new NowController();
                $details  = $nowModel->get(['tid' => $tid, 'timezone' => $timezone, 'longitude' => $longitude, 'latitude' => $latitude, 'datetime' => $datetime]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'natal':
                $natalModel = new NatalController();
                $details    = $natalModel->get(['id' => $id]);
                return show(config('code.success'), 'Success', $details);
                break;
            case 'transits':
                $transitsModel = new TransitsController();
                $details       = $transitsModel->get($datetime, $timezone, $id, true);
                return show(config('code.success'), 'Success', $details);
                break;
            case 'thirdprogressed':
                $thirdprogressedModel = new ThirdprogressedController();
                $details              = $thirdprogressedModel->get($datetime, true, $timezone, $id, true);
                return show(config('code.success'), 'Success', $details);
                break;
            case 'progressions':
                $progressionsModel = new ProgressionsController();
                $details           = $progressionsModel->get(['datetime' => $datetime, 'timezone' => $timezone, 'id' => $id]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'progressionsvsnatal':
                $progressionsvsnatalModel = new ProgressionsvsnatalController();
                $details                  = $progressionsvsnatalModel->get(['datetime' => $datetime, 'timezone' => $timezone, 'id' => $id]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'solar':
                $solarModel = new SolarController();
                $details    = $solarModel->get(['datetime' => $datetime, 'timezone' => $timezone, 'id' => $id]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'solar_return':
                $solar_returnModel = new SolarreturnController();
                $details           = $solar_returnModel->get(['datetime' => $datetime, 'timezone' => $timezone, 'id' => $id]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'lunar_return':
                $lunar_returnModel = new LunarreturnController();
                $details           = $lunar_returnModel->get(['datetime' => $datetime, 'timezone' => $timezone, 'id' => $id]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'firdaria':
                $firdariaModel = new FirdariaController();
                $details       = $firdariaModel->get(['datetime' => $datetime, 'timezone' => $timezone, 'id' => $id]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'profection':
                $profectionModel = new ProfectionController();
                $details         = $profectionModel->get(['datetime' => $datetime, 'timezone' => $timezone, 'id' => $id]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'synastry':
                $synastryModel = new SynastryController();
                $details       = $synastryModel->get(['id1' => $id1, 'id2' => $id2]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'composite':
                $compositeModel = new CompositeController();
                $details        = $compositeModel->get(['id1' => $id1, 'id2' => $id2]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'composite_thirdprogressed':
                $composite_thirdprogressedModel = new CompositethirdprogressedController();
                $details                        = $composite_thirdprogressedModel->get(['datetime' => $datetime, 'timezone' => $timezone, 'id1' => $id1, 'id2' => $id2]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'composite_progressions':
                $composite_progressionsModel = new CompositeprogressionsController();
                $details                     = $composite_progressionsModel->get(['datetime' => $datetime, 'timezone' => $timezone, 'id1' => $id1, 'id2' => $id2]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'davison':
                $davisonModel = new DavisonController();
                $details      = $davisonModel->get(['id1' => $id1, 'id2' => $id2]);
                return show(config('code.success'), 'Success.', $details);
                break;
            case 'marks':
                $dmarksModel = new MarksController();
                $details     = $dmarksModel->get(['id1' => $id1, 'id2' => $id2]);
                return show(config('code.success'), 'Success.', $details);
                break;
        }

    }
}
